home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MotifCheckBoxMenuItemUI.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  124 lines

  1. /*
  2.  * @(#)MotifCheckBoxMenuItemUI.java    1.31 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.motif;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.event.*;
  25. import com.sun.java.swing.plaf.*;
  26. import com.sun.java.swing.plaf.basic.BasicButtonListener;
  27. import com.sun.java.swing.plaf.basic.BasicCheckBoxMenuItemUI;
  28. import com.sun.java.swing.plaf.basic.BasicGraphicsUtils;
  29.  
  30. import java.awt.*;
  31. import java.awt.event.*;
  32. import java.io.Serializable;
  33.  
  34.  
  35. /**
  36.  * MotifCheckboxMenuItem implementation
  37.  * <p>
  38.  * Warning: serialized objects of this class will not be compatible with
  39.  * future swing releases.  The current serialization support is appropriate
  40.  * for short term storage or RMI between Swing1.0 applications.  It will
  41.  * not be possible to load serialized Swing1.0 objects with future releases
  42.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  43.  * baseline for the serialized form of Swing objects.
  44.  *
  45.  * @version 1.31 02/02/98
  46.  * @author Georges Saab
  47.  * @author Rich Schiavi
  48.  */
  49. public class MotifCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI
  50. {
  51.     protected ChangeListener changeListener;
  52.  
  53.     public static ComponentUI createUI(JComponent b) {
  54.         return new MotifCheckBoxMenuItemUI();
  55.     }
  56.  
  57.     protected void initListeners(JComponent c) {
  58.     super.initListeners(c);
  59.         changeListener = createChangeListener(c);
  60.     }
  61.     
  62.     protected void addListeners(JComponent c) {
  63.     super.addListeners(c);
  64.         ((JMenuItem)c).addChangeListener(changeListener);    
  65.     }
  66.  
  67.     protected void removeListeners(JComponent c) {
  68.     super.removeListeners(c);
  69.     ((JMenuItem)c).removeChangeListener(changeListener);
  70.     }
  71.  
  72.     protected ChangeListener createChangeListener(JComponent c) {
  73.     return new MenuChangeListener();
  74.     }
  75.  
  76.     protected class MenuChangeListener implements ChangeListener, Serializable {
  77.  
  78.  
  79.     public void stateChanged(ChangeEvent e) {
  80.         JMenuItem c = (JMenuItem)e.getSource();
  81.         if (c.isArmed()) {
  82.         c.setBorderPainted(true);
  83.         } else {
  84.         c.setBorderPainted(false);
  85.         }
  86.     }
  87.     }
  88.  
  89.     public void paint(Graphics g, JComponent c) {
  90.     MotifGraphicsUtils.paintMenuItem(g, c, ((JCheckBoxMenuItem)c).getSelectedIcon(),menuArrow,
  91.                      pressedBackground, pressedForeground,
  92.                      defaultTextIconGap);
  93.     }
  94.  
  95.  
  96.     public void processMouseEvent(JMenuItem item,MouseEvent e,MenuElement path[],MenuSelectionManager manager) {
  97.         Point p = e.getPoint();
  98.         if(p.x >= 0 && p.x < item.getWidth() &&
  99.            p.y >= 0 && p.y < item.getHeight()) {
  100.             if(e.getID() == MouseEvent.MOUSE_RELEASED) {
  101.                 manager.clearSelectedPath();
  102.                 item.doClick(0);
  103.             } else if(e.getID() == MouseEvent.MOUSE_DRAGGED || e.getID() == MouseEvent.MOUSE_PRESSED)
  104.                 manager.setSelectedPath(path);
  105.         } else if(item.getModel().isArmed() && e.getID() == MouseEvent.MOUSE_DRAGGED) {
  106.             MenuElement newPath[] = new MenuElement[path.length-1];
  107.             int i,c;
  108.             for(i=0,c=path.length-1;i<c;i++)
  109.                 newPath[i] = path[i];
  110.             manager.setSelectedPath(newPath);
  111.         }
  112.     }
  113.  
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.